package com.hellpro.lolbox.acticity.view;

import android.content.Context;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.hellpro.lolbox.factory.ContentRedFragmentFactory;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.acticity.presenter.MainActivityPresenter;
import com.hellpro.lolbox.base.LolBaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class RedActivity extends LolBaseActivity implements IRedActivity {


    @BindView(R.id.red_tv_return)
    TextView redTvReturn;
    @BindView(R.id.red_vp)
    ViewPager redVp;
    @BindView(R.id.red_tab_layout)
    TabLayout redTabLayout;

    @Override
    public int getLayoutId() {
        return R.layout.activity_red;
    }

    @Override
    public void initView() {
        redTabLayout.setTabTextColors(Color.GRAY,Color.parseColor("#F56161"));//设置选择和未选择的颜色
        redTabLayout.setupWithViewPager(redVp, true);//设置tablayout和viewpager关联 是否自动刷新
        redTabLayout.setTabMode(TabLayout.MODE_FIXED);//设置导航的模式
        redTabLayout.setSelectedTabIndicatorColor(Color.parseColor("#F56161") );//设置指示器的颜色
        redTabLayout.setSelectedTabIndicatorHeight(4);//设置指示器的宽度

        MainActivityPresenter presenter = new MainActivityPresenter(this,this);
        presenter.setRedViewPager();
        redTvReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public TextView getRedReturn() {
        return redTvReturn;
    }

    @Override
    public ViewPager getRedViewPager() {
        return redVp;
    }

    @Override
    public TabLayout getTabLayout() {
        return redTabLayout;
    }

    @Override
    public FragmentManager getVpFragmentManager() {
        return getSupportFragmentManager();
    }

    @Override
    public String[] getTitles() {
        return getResources().getStringArray(R.array.red_tab_array);
    }

    @Override
    public List<Fragment> getFragments() {
        List<Fragment> list = new ArrayList<>();
        for (int i = 0; i < getTitles().length; i++) {
            Fragment fragment = ContentRedFragmentFactory.createFragment(i);
            list.add(fragment);
        }
        return list;
    }

    @Override
    public Context getRedContext() {
        return RedActivity.this;
    }

}
